<template>
    <div class="edu-page-warp">
        <el-card shadow="never" body-style="padding: 24px;">
            <el-form :model="queryForm" label-width="80px">
                <el-row :gutter="24" style="height: 50px;">
                    <el-col :span="24">
                        <div class="title-one">筛选条件</div>
                        <div style="float:right;">
                            <el-button size="mini" @click="resetSearch">重置</el-button>
                            <el-button size="mini" type="primary" @click="searchCollegeMajorInfo">筛选</el-button>
                        </div>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="6">
                        <el-form-item label="辅修学年:" prop="minorGrade" class="no-bottom">
                            <el-date-picker
                                style="width:100%"
                                v-model="queryForm.minorGrade"
                                type="year"
                                value-format="yyyy"
                                placeholder="请选择"
                                @change="minorGradeChange"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="辅修学校:" prop="schoolId" class="no-bottom">
                            <el-select
                                clearable
                                v-model="queryForm.schoolId"
                                placeholder="请选择"
                                :filterable="true"
                                style="width:100%"
                                @change="queryAdvancedLevelBySchoolId"
                            >
                                <el-option
                                    v-for="item in options.schoolId"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="辅修专业:" prop="minorMajorId" class="no-bottom">
                            <el-select
                                clearable
                                v-model="queryForm.minorMajorId"
                                placeholder="请选择"
                                style="width:100%"
                            >
                                <el-option
                                    v-for="item in options.minorMajorId"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="起点层次:" prop="advancedLevel" class="no-bottom">
                            <el-select
                                clearable
                                v-model="queryForm.advancedLevel"
                                style="width:100%"
                                placeholder="请选择"
                            >
                                <el-option
                                    v-for="item in options.advancedLevel"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div style="width:100%;height:2px;background-color:#D2D4D6"></div>
            <div class="diagDiv">
                <div class="tipsDiv" v-if="optionStatus">
                    {{minorGrade}}年专业参数配置有效时间为
                    <lable style="color: red;">{{applyBeginDate}}至{{applyEndDate}}</lable>，请在有效时间内进行配置
                </div>
                <div class="addButon" v-if="optionStatus">
                    <el-button @click="copyMinorMajorInfo">复制</el-button>
                    <el-button type="primary" @click="addMinorMajorInfo">新建</el-button>
                </div>
            </div>
            <edu-table
                ref="multipleTable"
                :data="tableData.list"
                @selection-change="chooseRow"
                @page-change="pageChange"
                :total="tableData.total_"
                :pageSize="queryForm.pageSize"
                :pageNum="queryForm.pageNum" 
                :order="false"
            >
                <el-table-column prop="minorYearName" label="辅修年级" show-overflow-tooltip></el-table-column>
                <el-table-column prop="majorNameZn" label="辅修专业名称" show-overflow-tooltip></el-table-column>
                <el-table-column prop="gradePoint" label="辅修绩点" show-overflow-tooltip></el-table-column>
                <el-table-column prop="prerequisiteTagName" label="先修课标签" show-overflow-tooltip></el-table-column>
                <el-table-column prop="year" label="年级限制" show-overflow-tooltip></el-table-column>
                <el-table-column prop="advancedLevelName" label="起点层次" show-overflow-tooltip></el-table-column>
                <el-table-column prop="createDate" label="创建时间" show-overflow-tooltip></el-table-column>
                <el-table-column prop="option" label="操作" v-if="reminderTag">
                    <template slot-scope="scope">
                        <el-button
                            @click="updateMinorMajorInfo(scope.row)"
                            type="text"
                            size="small"
                            v-if="optionStatus"
                        >编辑</el-button>
                        <el-button
                            type="text"
                            size="small"
                            @click="deleteMinorMajorInfo(scope.row)"
                        >删除</el-button>
                    </template>
                </el-table-column>
            </edu-table>
            <!-- 新增/修改辅修专业 -->
            <el-dialog
                :title="`${!dialogTiltle?'新增':'修改'}辅修专业 - ${minorGrade} （${schoolType}）`"
                :visible.sync="dialogTableVisible"
                width="600px"
                :close-on-click-modal="false"
            >
                <el-form
                    :model="form"
                    :rules="checkCollegeForm"
                    label-width="120px"
                    ref="collegeMajarForm"
                >
                    <el-form-item label="选择学校" prop="schoolId">
                        <el-row :gutter="20">
                            <el-col :span="16" class="rightCol">
                                <el-select
                                    clearable
                                    v-model="form.schoolId"
                                    placeholder="请选择学校"
                                    @change="queryAdvancedLevelBySchool"
                                    style="width:100%;"
                                >
                                    <el-option
                                        v-for="item in options.schoolId"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-col>
                        </el-row>
                    </el-form-item>
                    <el-form-item label="专业名称" prop="minorMajorId">
                        <el-row :gutter="20">
                            <el-col :span="16" class="rightCol">
                                <el-select
                                    clearable
                                    v-model="form.minorMajorId"
                                    placeholder="请选择"
                                    style="width:100%;"
                                >
                                    <el-option
                                        v-for="item in dialogOptions.minorMajorId"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-col>
                        </el-row>
                    </el-form-item>
                    <el-form-item label="起点层次" prop="advancedLevel">
                        <el-row :gutter="20">
                            <el-col :span="16" class="rightCol">
                                <el-select
                                    clearable
                                    v-model="form.advancedLevel"
                                    style="width:100%;"
                                    placeholder="请选择"
                                >
                                    <el-option
                                        v-for="item in dialogOptions.advancedLevel"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-col>
                        </el-row>
                    </el-form-item>
                    
                    <el-form-item label="辅修绩点" prop="prePoint">
                        <el-row :gutter="20">
                            <el-col :span="16" class="rightCol">
                                <el-input
                                    v-model="form.prePoint"
                                    @change="checkInputValue(form.prePoint,5)"
                                    autocomplete="off"
                                ></el-input>
                            </el-col>
                        </el-row>
                    </el-form-item>
                    <el-form-item label="年级限制">
                        <el-row :gutter="20">
                            <el-col :span="16" class="rightCol">
                                <el-select
                                    v-model="form.gradeLimit"
                                    filterable
                                    multiple
                                    style="width:100%;"
                                    placeholder="请选择"
                                >
                                    <el-option
                                        v-for="item in options.gradeLimit"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-col>
                        </el-row>
                    </el-form-item>
                    <el-form-item label="录取说明">
                        <el-row :gutter="20">
                            <el-col :span="16" class="rightCol">
                                <el-input
                                    type="textarea"
                                    v-model="form.recruitRemark"
                                    autocomplete="off"
                                ></el-input>
                            </el-col>
                        </el-row>
                    </el-form-item>
                    <div class="preDiv">
                        <el-row :gutter="20">
                            <el-col :span="6">
                                <div class="addDiv">先修课标签</div>
                            </el-col>
                            <el-col :span="16">
                                <div class="addDiv">
                                    <el-button type="text" size="small" @click="addPreTag">添加</el-button>
                                </div>
                            </el-col>
                        </el-row>
                    </div>
                    <div class="preList" v-for="(item,i) in form.list" :key="i">
                        <el-row :gutter="20">
                            <el-col :span="14">
                                <div style="margin-left: 46px;">
                                    <el-select
                                        v-model="item.tagName"
                                        filterable
                                        style="width:100%;"
                                        placeholder="请选择"
                                    >
                                        <el-option
                                            v-for="item in options.tagName"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </div>
                            </el-col>
                            <el-col :span="6">
                                <div style="margin-left: 8px;">
                                    <el-input
                                        :id="i"
                                        v-model="item.proprePoint"
                                        @change="checkInputTagValue(item.proprePoint,5)"
                                        autocomplete="off"
                                    ></el-input>
                                </div>
                            </el-col>
                            <el-col :span="2">
                                <div class="addDiv">
                                    <el-button type="text" size="small" @click="delPreTag(i)">删除</el-button>
                                </div>
                            </el-col>
                        </el-row>
                    </div>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogTableVisible = false">取 消</el-button>
                    <el-button
                        type="primary"
                        v-if="optionButton"
                        @click="updateCollegeMajorInfo"
                    >确 定</el-button>
                    <el-button type="primary" v-else @click="addCollegeMajorInfo">确 定</el-button>
                </div>
            </el-dialog>
            <!-- 复制辅修专业 -->
            <el-dialog
                :title="`复制辅修专业（${!copyTitle?'学校管理员':'学院教务员'}）`"
                :visible.sync="copydilalog"
                width="600px"
                :close-on-click-modal="false"
            >
                <el-form ref="copyForm" :model="copyForm" :rules="checkCopyForm">
                    <el-row :gutter="20">
                        <el-col :span="20">
                            <el-form-item label="辅修专业" prop="majorName" label-width="160px">
                                <el-input
                                    style="width:100%"
                                    v-model="copyForm.majorName" readonly>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="20">
                            <el-form-item label="从" prop="oldMinorGrade" label-width="160px">
                                <el-date-picker
                                    style="width:100%"
                                    v-model="copyForm.oldMinorGrade"
                                    type="year"
                                    readonly
                                    value-format="yyyy"
                                    placeholder="选择年级"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="20">
                            <el-form-item label="复制到" prop="newMinorGrade" label-width="160px">
                                <el-date-picker
                                    style="width:100%"
                                    v-model="copyForm.newMinorGrade"
                                    type="year"
                                    value-format="yyyy"
                                    placeholder="选择年级"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="20">
                            <el-form-item label="年级限制" prop="majorName" label-width="160px">
                                <el-select
                                    v-model="form.gradeLimit"
                                    filterable
                                    multiple
                                    style="width:100%;"
                                    placeholder="请选择"
                                >
                                    <el-option
                                        v-for="item in options.gradeLimit"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <el-row :gutter="24">
                    <el-col :span="24">
                        <div class="float-right">
                            <el-button @click="copydilalog = false">取 消</el-button>
                            <el-button type="primary" @click="inserCopyMinorInfo">复制</el-button>
                        </div>
                    </el-col>
                </el-row>
            </el-dialog>
        </el-card>
    </div>
</template>
<script>
import { queryDic } from "common/src/api/dictionary";
import Calendars from "common/src/api/calendars";
import { getSessionUser } from "common/src/api/session";
import UTILS from "common/src/utils/utils";
import * as INDEX from "common/src/utils/index";

import {
    queryAdvancedLevel,
    queryMinorMajorInfo,
    queryUniversityDicByIsOnCampus,
    queryGradeLimitInfo,
    insertCollegeMajorInfo,
    queryPreCourseTagList,
    deleteCollegeMajorInfo,
    queryCollegeMajorList,
    inserCopyCollegeMajorInfo,
    updateCollegeMajorInfo,
    queryMinorConfigInfo
} from "common/src/api/minor/collegemajor";
import nocursor from "common/src/directives/nocursor";
import mixin from 'common/src/mixins/index';
export default {
    mixins: [mixin],
    data() {
        return {
            dialogTableVisible: false,
            copydilalog: false,
            schoolShow: false,
            optionStatus: true,
            dialogTiltle: true,
            optionButton: false,
            copyTitle: true,
            minorGrade: "",
            chooseRows: [],
            accountType: "",
            schoolList: [],
            tagIds: [],
            pointList: [],
            schoolGradeYear: "",
            minorMajorList: [],
            applyBeginDate: "",
            applyEndDate: "",
            reminderTag: true,
            schoolType: "校内",
            copyForm: {
                majorName: "",
                oldMinorGrade: "",
                newMinorGrade: ""
            },
            form: {
                schoolId: "",
                advancedLevel: "",
                minorMajorId: "",
                prePoint: "",
                gradeLimit: [],
                recruitRemark: "",
                list: [{ tagName: "", proprePoint: "" }]
            },
            queryForm: {
                advancedLevel: "",
                minorMajorId: "",
                minorGrade: "",
                schoolId: "",
                pageNum: 1,
                pageSize: 20
            },
            options: {
                advancedLevel: [],
                minorMajorId: [],
                schoolId: [],
                gradeLimit: [],
                tagName: []
            },
            tableData: {},
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                collegeMajorId: ""
            },
            checkCopyForm: {
                oldMinorGrade: [
                    {
                        required: true,
                        message: "请选择复制开始时间",
                        trigger: "change"
                    }
                ],
                newMinorGrade: [
                    {
                        required: true,
                        message: "请选择复制结束时间",
                        trigger: "change"
                    }
                ]
            },
            checkCollegeForm: {
                schoolId: [
                    {
                        required: true,
                        message: "请选择学校",
                        trigger: "change"
                    }
                ],
                advancedLevel: [
                    {
                        required: true,
                        message: "请选择进阶层次",
                        trigger: "change"
                    }
                ],
                minorMajorId: [
                    { required: true, message: "请选择专业", trigger: "change" }
                ],
                prePoint: [
                    {
                        required: true,
                        message: "请输入辅修绩点",
                        trigger: "blur"
                    }
                ]
            },
            dialogOptions: {
                advancedLevel: [],
                minorMajorId: []
            }
        };
    },
    directives: {
        nocursor
    },
    mounted() {
        if (!this.$checkMinor()) return;
        this.minorGradeLoad = false;
        this.getType(); //获取角色类型
        this.initGradeLimit();
        queryMinorConfigInfo("").then(res => {
            if (res.code == 200) {
                this.minorGrade = res.data[0].grade;
                this.queryForm.minorGrade =  this.minorGrade;
                if (
                    res.data[0].configSwitch != "0" ||
                    (res.data[0].configSwitchStartTime != null &&
                        res.data[0].configSwitchEndTime != null)
                ) {
                    this.applyBeginDate = INDEX.parseTime(
                        res.data[0].configSwitchStartTime
                    );
                    this.applyEndDate = INDEX.parseTime(
                        res.data[0].configSwitchEndTime
                    );
                    if (
                        res.data[0].configSwitchStartTime <=
                            new Date().getTime() &&
                        new Date().getTime() <= res.data[0].configSwitchEndTime
                    ) {
                        this.reminderTag = true;
                        this.optionStatus = true;
                    } else {
                        this.reminderTag = false;
                        this.optionStatus = false;
                    }
                } else {
                    this.reminderTag = false;
                    this.optionStatus = false;
                }
            }
        }).finally(()=>{
            this.minorGradeLoad = true;
            if (this.global.isAcdemicDean) {
                if (this.schoolLoad) {
                    this.queryAdvancedLevelBySchoolId();
                    this.searchCollegeMajorInfo();
                }
            }else {
                if (this.minorGrade) {
                    this.minorGradeChange();
                }
                this.initMajorList();
            }
        })
        
    },
    methods: {
        //获取当前登录角色权限信息
        getType() {
            // getSessionUser().then(res => {
            //     if ((res.code = 200)) {
            //         //校管理员登录
            //         if (
            //             res.data.user.innerRoles.join(",").indexOf("1") >= 0 &&
            //             res.data.user.currentRole == "1"
            //         ) {
            //             this.accountType = "1";
            //             this.schoolShow = true;
            //             this.options["advancedLevel"] = [];
            //             this.initAdvancedLevel("1", this.options["advancedLevel"]);
            //             this.initSchoolList("");
            //             //院教务员登录
            //         } else if (
            //             res.data.user.innerRoles.join(",").indexOf("2") >= 0 &&
            //             res.data.user.currentRole == "1"
            //         ) {
            //             this.accountType = "0";
            //             this.schoolShow = false;
            //             this.options["advancedLevel"] = [];
            //             this.initAdvancedLevel("0", this.options["advancedLevel"]);
            //             this.initSchoolList("0");
            //         }
            //     }
            // });
            if (this.global.isAdmin) {
                this.accountType = "1";
                this.schoolShow = true;
                this.options["advancedLevel"] = [];
                this.initAdvancedLevel("", this.options["advancedLevel"]);
                this.initSchoolList("");
            }else if(this.global.isAcdemicDean) {
                this.accountType = "0";
                this.schoolShow = false;
                this.options["advancedLevel"] = [];
                //this.initAdvancedLevel("0", this.options["advancedLevel"]);
                this.initSchoolList("0");
            }
        },
        minorGradeChange() {
            this.options["minorMajorId"] = [];
            this.queryForm.minorMajorId = "";
            this.queryMinorMajorqueryMinorMajor({
                schoolId: this.queryForm.schoolId
            }, this.options["minorMajorId"]);
        },
        //请求列表数据
        initMajorList() {
            if (!this.$checkMinor()) return;
            let param = {};
            for (let attr in this.queryForm) {
                let item = attr;
                // if (attr == 'advancedLevel') {
                //     item = 'advancedLevelCode';
                // }
                if (attr == 'schoolId') {
                    item = 'shoolId';
                }
                param[item] = this.queryForm[attr]; 
            }
            queryCollegeMajorList(param).then(res => {
                if (res.code == 200 && res.data.list.length > 0) {
                    const data = res.data.list;
                    data.forEach(e => {
                        e.createDate = !e.createDate
                            ? null
                            : INDEX.parseTime(e.createDate);
                    });
                    this.tableData = {
                        list: data ? data : [],
                        total_: res.data.total_
                    };
                } else {
                    this.tableData = {};
                }
            });
        },
        checkInputValue(e, num) {
            var regu = /^[0-9]+\.?[0-9]*$/;
            var reguTwo = /^[0-9]*$/;
            if (e != "") {
                if (reguTwo.test(e)) {
                    if (e.substring(0, 1) == "0") {
                        this.$message.warning("请输入正确绩点");
                        return false;
                    }
                } else {
                    if (regu.test(e)) {
                        if (e.indexOf(".") > -1) {
                            if (e.split(".")[1].length > num) {
                                this.$message.warning("请输入正确绩点");
                                return false;
                            } else if (e.split(".")[1] == "") {
                                this.$message.warning("请输入正确绩点");
                                return false;
                            }
                        }
                    } else {
                        this.$message.warning("请输入正确绩点");
                        return false;
                    }
                }
            }
            return true;
        },
        checkInputTagValue(e, num) {
            return this.checkInputValue(e, num);
        },
        //格式化日期
        returnDateStr(year, month, day) {
            month = month < 9 ? "0" + month : "" + month;
            day = day < 9 ? `0{${day}}` : "" + day;
            return year + "-" + month + "-" + day;
        },
        initPreTagList() {
            queryPreCourseTagList("").then(res => {
                if (res.code == 200) {
                    for (let key = 0; key < res.data.length; key++) {
                        this.options["tagName"].push({
                            value: res.data[key].prerequisiteTagId + "",
                            label: res.data[key].prerequisiteTagName
                        });
                    }
                }
            });
        },
        initGradeLimit() {
            queryGradeLimitInfo("").then(res => {
                if (res.code == 200) {
                    this.options["gradeLimit"] = [];
                    for (let key = 0; key < res.data.length; key++) {
                        this.options["gradeLimit"].push({
                            value: res.data[key].gradeLimitId,
                            label: res.data[key].yearName
                        });
                    }
                }
            });
        },
        initSchoolList(isOnCampus) {
            let params = {
                isOnCampus: isOnCampus
            };
            this.schoolLoad = false;
            queryUniversityDicByIsOnCampus(params).then(res => {
                if (res.code == 200) {
                    this.options.schoolId = [];
                    for (let key = 0; key < res.data.length; key++) {
                        this.options["schoolId"].push({
                            value: res.data[key].minorUniversityCode,
                            label: res.data[key].minorUniversityName
                        });
                    }
                    this.schoolList = res.data;
                }
            }).finally(() =>{
                if (isOnCampus === '0') {
                    this.options.schoolId = this.options.schoolId.filter(item => {
                        return item.value == '10001';//教务员只展示同济大学
                    })
                    this.queryForm.schoolId = this.options.schoolId[0] && this.options.schoolId[0].value;
                    this.schoolLoad = true;
                    if (this.minorGradeLoad) {
                        this.queryAdvancedLevelBySchoolId();
                        this.searchCollegeMajorInfo();
                    }
                }else {
                    this.queryForm.schoolId = '';
                }
            })
        },
        //表格复选框选中或取消
        chooseRow(val) {
            this.chooseRows = val;
        },
        initAdvancedLevel(isOnCampus, option) {
            let params = {
                isOnCampus: isOnCampus
            };
            queryAdvancedLevel(params).then(res => {
                if (res.code == 200) {
                    for (let key = 0; key < res.data.length; key++) {
                        (option || []).push({
                            value: res.data[key].advancedLevelCode,
                            label: res.data[key].advancedLevelName
                        });
                    }
                }
            });
        },
        queryAdvancedLevelBySchool() {
            let isOnCampus = "0";
            this.schoolList.length > 0 &&
                this.schoolList.forEach(e => {
                    if (e.minorUniversityCode == this.form.schoolId) {
                        isOnCampus = e.isOnCampus;
                    }
                });
            this.dialogOptions["minorMajorId"] = [];
            this.dialogOptions["advancedLevel"] = [];
            this.form.advancedLevel = "";
            this.form.minorMajorId = "";
            //根据选择的学校显示学校类型
            if ("0" == isOnCampus) {
                this.schoolType = "校内";
            } else {
                this.schoolType = "校外";
            }
            this.initAdvancedLevel(isOnCampus, this.dialogOptions["advancedLevel"]);
            this.queryMinorMajorqueryMinorMajor({
                schoolId: this.form.schoolId
            }, this.dialogOptions["minorMajorId"]);
        },
        queryMinorMajorCondition() {
            let params = {
                schoolId: ""
            };
            this.queryMinorMajorqueryMinorMajor(params);
        },
        queryMinorMajorqueryMinorMajor(params, option) {
            if (!this.$checkMinor()) return;
            params.status = 1;
            params.minorGrade = this.queryForm.minorGrade;
            queryMinorMajorInfo(params).then(res => {
                if (res.code == 200) {
                    for (let key = 0; key < res.data.list.length; key++) {
                        (option || []).push({
                            value: res.data.list[key].majorCode,
                            label: res.data.list[key].majorNameZh
                        });
                    }
                }
            });
        },
        addPreTag() {
            this.form.list.push({ tagName: "", proprePoint: "" });
        },
        delPreTag(i) {
            if (this.form.list.length > 0) {
                this.form.list.splice(i, 1);
            }
        },
        addMinorMajorInfo() {
            if (!this.$checkMinor()) return;
            //清空学校的下拉内容
            //this.options.schoolId = [];
            this.schoolType = "校内";
            // getSessionUser().then(res => {
            //     if ((res.code = 200)) {
            //         //校管理员
            //         if (
            //             res.data.user.innerRoles.join(",").indexOf("1") >= 0 &&
            //             res.data.user.currentRole == "1"
            //         ) {
            //             this.dialogOptions["advancedLevel"] = [];
            //             this.initAdvancedLevel("1",  this.dialogOptions["advancedLevel"]);
            //             //this.initSchoolList("");
            //         } else if (
            //             //学院教务员
            //             res.data.user.innerRoles.join(",").indexOf("2") >= 0 &&
            //             res.data.user.currentRole == "1"
            //         ) {
            //             this.dialogOptions["advancedLevel"] = [];
            //             this.initAdvancedLevel("0",  this.dialogOptions["advancedLevel"]);
            //             //this.initSchoolList("0");
            //         }
            //     }
            // });
            this.dialogOptions.minorMajorId = [];
            //this.initGradeLimit();
            this.initPreTagList();
            this.dialogTableVisible = true;
            this.dialogTiltle = false;
            this.optionButton = false;
            this.form = {
                schoolId: "",
                advancedLevel: "",
                minorMajorId: "",
                prePoint: "",
                gradeLimit: [],
                recruitRemark: "",
                list: []
            };
            if (this.accountType === '0') {
               this.form.schoolId = this.options.schoolId[0] && this.options.schoolId[0].value;
               this.queryAdvancedLevelBySchool();
            }
            // this.queryForm = {
            //     advancedLevel: "",
            //     minorMajorId: ""
            // };
            //清空先修课标签
            this.options.tagName = [];
            this.$refs.collegeMajarForm &&
                this.$refs.collegeMajarForm.resetFields();
        },
        async updateMinorMajorInfo(row) {
            this.options.tagName = [];
            this.dialogOptions.advancedLevel = [];
            this.dialogOptions.minorMajorId = [];
            //this.initGradeLimit();
            this.initPreTagList();
            this.form = {
                schoolId: "",
                advancedLevel: "",
                minorMajorId: "",
                prePoint: "",
                gradeLimit: [],
                recruitRemark: "",
                list: []
            };
            this.queryParams = {
                pageNum_: 1,
                pageSize_: 20,
                collegeMajorId: "",
                condition: {
                    calendarId: null
                }
            };
            this.copyForm = {
                oldMinorGrade: "",
                newMinorGrade: ""
            };
            this.dialogTableVisible = true;
            this.dialogTiltle = true;
            this.optionButton = true;
            let type = this.accountType;
            //设置学校类型
            let schoolInOut = "0";
            this.schoolList.length > 0 &&
                this.schoolList.forEach(e => {
                    if (e.minorUniversityCode == row.minorSchool) {
                        schoolInOut = e.isOnCampus;
                    }
                });
            //初始化参数
            if ("0" == schoolInOut) {
                this.schoolType = "校内";
            } else {
                this.schoolType = "校外";
            }
            this.form.schoolId = row.minorSchool;
            this.form.prePoint = row.gradePoint;
            this.queryParams.collegeMajorId = row.collegeMajorId;
            if (row.gradeLimitId != null) {
                let dataStrArr = row.gradeLimitId.split(",");
                let dataIntArr = [];
                dataStrArr.forEach(item => {
                    dataIntArr.push(+item);
                });
                this.form.gradeLimit = dataIntArr;
            }
            this.form.recruitRemark = row.adminssionExplain;
            if (row.prerequisiteTagId != null) {
                this.tagIds = row.prerequisiteTagId + "";
                this.pointList = row.prerequisitePoint;
                for (let i = 0; i < this.tagIds.split(",").length; i++) {
                    this.form.list.push({
                        tagName: this.tagIds.split(",")[i],
                        proprePoint: this.pointList.split(",")[i]
                    });
                }
            }
            this.dialogTableVisible = true;
            this.initAdvancedLevel(schoolInOut, this.dialogOptions["advancedLevel"]);
            await this.queryMinorMajorqueryMinorMajor({
                schoolId: this.form.schoolId
            }, this.dialogOptions["minorMajorId"]);
            this.form.advancedLevel = row.advancedLevelCode;
            this.form.minorMajorId = row.majorId;
            this.$refs.collegeMajarForm &&
                this.$refs.collegeMajarForm.resetFields();
        },
        addQueryMajorInfo() {
            let params = {
                advancedLevelCode: this.form.advancedLevel,
                minorUniversityCode: this.form.schoolId
            };
            this.queryMinorMajorqueryMinorMajor(params);
        },
        addCollegeMajorInfo() {
            this.$refs.collegeMajarForm.validate(valid => {
                if (valid) {
                    if (this.checkInputValue(this.form.prePoint, 5)) {
                        //初始化学校
                        // if (this.accountType == "1") {
                        //     this.initSchoolList("");
                        // } else {
                        //     this.initSchoolList("0");
                        // }
                        let flagSign = true;
                        let tagMap = {};
                        // this.form.list.length > 0 &&
                        //     this.form.list.forEach(e => {
                        //         //校验标签是否选择相同的
                        //         if (tags == e.tagName + "") {
                        //             this.$message.warning("先修课标签不能重复");
                        //             flag = 1;
                        //             return;
                        //         } else {
                        //             if (e.proprePoint.length != 0) {
                        //                 if (
                        //                     !this.checkInputTagValue(
                        //                         e.proprePoint,
                        //                         5
                        //                     )
                        //                 ) {
                        //                     flag = 1;
                        //                     return;
                        //                 } else {
                        //                     tagMap[e.tagName] = e.proprePoint;
                        //                     tags = e.tagName + "";
                        //                 }
                        //             } else {
                        //                 if (e.tagName != "") {
                        //                     this.$message.warning(
                        //                         "请输入先修课绩点"
                        //                     );
                        //                     flag = 1;
                        //                     return;
                        //                 }
                        //             }
                        //         }
                        //     });
                        this.form.list.length >0  && this.form.list.forEach((item, index) => {
                            if (!flagSign) return;
                            if (item.tagName != ''){
                                if (item.proprePoint.length == 0) {
                                    flagSign = false;
                                    this.$message.warning("请输入先修课绩点");
                                }else {
                                    let sameItem = this.form.list.find((e, key) => {
                                        return e.tagName == item.tagName && index != key;
                                    })
                                    if (sameItem) {
                                        flagSign = false;
                                        this.$message.warning("先修课标签不能重复");
                                    }else {
                                        tagMap[item.tagName] = item.proprePoint;
                                    }
                                }
                            }else {
                                if (item.proprePoint.length != 0) {
                                    flagSign = false;
                                    this.$message.warning("请选择先修课标签");
                                }
                            }

                        })
                        if (flagSign) {
                            let params = {
                                minorGrade: this.minorGrade, //this.schoolGradeYear,
                                shoolId: this.form.schoolId,
                                advancedLevel: this.form.advancedLevel,
                                minorMajorId: this.form.minorMajorId,
                                minorPoint: this.form.prePoint,
                                gradeList: this.form.gradeLimit.toString(),
                                admissionExplain: this.form.recruitRemark,
                                tagMap: tagMap
                            };

                            insertCollegeMajorInfo(params).then(res => {
                                if (res.code == 200) {
                                    this.$message.success("新增成功");
                                    this.dialogTableVisible = false;
                                    this.searchCollegeMajorInfo();
                                }
                            });
                        }
                    }
                } else {
                    return false;
                }
            });
        },
        copyMinorMajorInfo() {
            this.copyForm.oldMinorGrade = "";
            this.copyForm.newMinorGrade = "";
            this.form.gradeLimit = [];
            if (this.chooseRows.length == 0) {
                this.$message({
                    type: "warning",
                    message: "请选择要复制的专业"
                });
                return;
            }
            this.minorMajorList = [];
            this.chooseRows.length > 0 &&
                this.chooseRows.forEach(e => {
                    if (e.majorNameZn != null) {
                        this.minorMajorList.push({
                            minorMajorName: e.majorNameZn
                        });
                        this.copyForm.oldMinorGrade = e.minorGrade;
                    }
                });
            if (this.minorMajorList.length > 1) {
                this.$message({
                    type: "warning",
                    message: "只能选择一条专业复制"
                });
                return;
            } else {
                this.copyForm.majorName = this.minorMajorList[0].minorMajorName;
                this.copydilalog = true;
            }
            //this.initGradeLimit();
        },
        inserCopyMinorInfo() {
            this.$refs.copyForm.validate(valid => {
                if (valid) {
                    let majorMinorId = "";
                    this.chooseRows.length > 0 &&
                        this.chooseRows.forEach(e => {
                            if (e.collegeMajorId != null) {
                                if (majorMinorId.length != 0) {
                                    majorMinorId += "," + e.collegeMajorId;
                                } else {
                                    majorMinorId += e.collegeMajorId;
                                }
                            }
                        });
                    let params = {
                        majorCode: majorMinorId,
                        oldMinorGrade: this.copyForm.oldMinorGrade,
                        newMinorGrade: this.copyForm.newMinorGrade,
                        gradeLimit: this.form.gradeLimit.toString()
                    };
                    if (
                        this.copyForm.newMinorGrade * 1 <=
                        this.copyForm.oldMinorGrade * 1
                    ) {
                        this.$message({
                            type: "warning",
                            message: "目标辅修学年必须在起始学年之后"
                        });
                        return;
                    } else {
                        inserCopyCollegeMajorInfo(params).then(res => {
                            if (res.code == 200) {
                                this.$message({
                                    type: "success",
                                    message: res.msg || '复制成功'
                                });
                                this.copydilalog = false;
                                this.searchCollegeMajorInfo();
                            }
                        });
                    }
                } else {
                    return false;
                }
            });
        },
        deleteMinorMajorInfo(row) {
            let params = {
                collegeMajorId: row.collegeMajorId
            };
            this.$confirm(
                "是否删除学院专业参数配置",
                this.$t("message.prompt"),
                {
                    confirmButtonText: this.$t("message.confirm"),
                    cancelButtonText: this.$t("message.cancel"),
                    type: "warning"
                }
            ).then(() => {
                deleteCollegeMajorInfo(params).then(res => {
                    if (res.code == 200) {
                        this.$message.success("删除成功");
                        this.searchCollegeMajorInfo();
                    }
                });
            });
        },
        queryAdvancedLevelBySchoolId() {
            let isOnCampus = "";
            this.schoolList.length > 0 &&
                this.schoolList.forEach(e => {
                    if (e.minorUniversityCode == this.queryForm.schoolId) {
                        isOnCampus = e.isOnCampus;
                    }
                });
            this.options["advancedLevel"] = [];
            this.options["minorMajorId"] = [];
            this.queryForm.advancedLevel = "";
            this.queryForm.minorMajorId = "";
            this.initAdvancedLevel(isOnCampus,  this.options["advancedLevel"]);
            this.queryMinorMajorqueryMinorMajor({
                schoolId: this.queryForm.schoolId
            }, this.options["minorMajorId"]);
        },
        resetSearch() {
            this.queryForm.minorGrade = this.minorGrade;
            this.queryForm.calendarId = "";
            if (this.global.isAcdemicDean) {
                this.queryForm.schoolId = this.options.schoolId[0] && this.options.schoolId[0].value;
            }else {
                this.queryForm.schoolId = "";
            }
            this.queryForm.advancedLevel = "";
            this.queryForm.minorMajorId = "";
            this.queryAdvancedLevelBySchoolId();
            this.searchCollegeMajorInfo();
        },
        searchCollegeMajorInfo() {
            this.queryForm.pageNum = 1;
            this.initMajorList();
        },
        updateCollegeMajorInfo() {
            this.$refs.collegeMajarForm.validate(valid => {
                if (valid) {
                    if (this.checkInputValue(this.form.prePoint + "", 5)) {
                        let tagMap = {};
                        let flagSign = true;
                        this.form.list.length >0  && this.form.list.forEach((item, index) => {
                            if (!flagSign) return;
                            if (item.tagName != ''){
                                if (item.proprePoint.length == 0) {
                                    flagSign = false;
                                    this.$message.warning("请输入先修课绩点");
                                }else {
                                    let sameItem = this.form.list.find((e, key) => {
                                        console.log(key, index, 999)
                                        return e.tagName == item.tagName && index != key;
                                    })
                                    if (sameItem) {
                                        flagSign = false;
                                        this.$message.warning("先修课标签不能重复");
                                    }else {
                                        tagMap[item.tagName] = item.proprePoint;
                                    }
                                }
                            }else {
                                if (item.proprePoint.length != 0) {
                                    flagSign = false;
                                    this.$message.warning("请选择先修课标签");
                                }
                            }

                        })
                        if (flagSign) {
                            let params = {
                                minorGrade: this.minorGrade,
                                shoolId: this.form.schoolId,
                                advancedLevel: this.form.advancedLevel,
                                collegeMajorId: this.queryParams.collegeMajorId,
                                minorMajorId: this.form.minorMajorId,
                                minorPoint: this.form.prePoint,
                                gradeList: this.form.gradeLimit.toString(),
                                admissionExplain: this.form.recruitRemark,
                                tagMap: tagMap
                            };
                            updateCollegeMajorInfo(params).then(res => {
                                if (res.code == 200) {
                                    this.dialogTableVisible = false;
                                    this.searchCollegeMajorInfo();
                                    this.$message.success("编辑成功");
                                }
                            });
                        }
                    }
                }
            });
        },
        pageChange(page) {
            this.queryForm.pageNum = page.pageNum;
            this.queryForm.pageSize = page.pageSize;
            this.initMajorList();
        }
    }
};
</script>
<style scoped>
.title-one {
    font-size: 18px;
    font-family: "微软雅黑";
    float: left;
}
.rightCol {
    margin-left: 1rem;
}
.preDiv {
    border-bottom: 1px solid #e4e7ed;
    border-top: 1px solid #e4e7ed;
    line-height: 33px;
}
.addDiv {
    text-align: right;
}
.preList {
    padding-top: 3px;
    border-bottom: 1px solid #ebebeb;
    padding-bottom: 3px;
}
.diagDiv {
    margin-top: 25px;
}
.tipsDiv {
    float: left;
    width: 83%;
    margin-top: 16px;
    font-size: 12px;
}
.addButon {
    float: right;
    margin-bottom: 15px;
}
.listBottom {
    border-bottom: 1px solid #d2d4d6;
    padding: 0 0 0 8px;
}
</style>


